package com.shihb.chapter07designpattern.proxypattern

/**
 * Description:
 *
 * @author shihb
 * @date 2020/10/4 19:53
 */
object Test {
  def main(args: Array[String]): Unit = {
    val p:PersonInfo = new PersonInfoImpl
    val other = getNonOwnerInvocationHandler(p)
    val me = getOwnerInvocationHandler(p)
    me.setInfo("shb")
    me.setHobby("coding")
    me.setScore(100.00)
    println("info:"+me.getInfo+" hobby:"+me.getHobby+" score:"+me.getScore)
    other.setInfo("other")
    other.setHobby("other")
    other.setScore(50.00)
    println("info:"+other.getInfo+" hobby:"+other.getHobby+" score:"+other.getScore)


  }
  def getOwnerInvocationHandler(p: PersonInfo)={
    java.lang.reflect.Proxy.newProxyInstance(p.getClass.getClassLoader,p.getClass.getInterfaces,new OwnerInvocationHandler(p)).asInstanceOf[PersonInfo]
  }
  def getNonOwnerInvocationHandler(p: PersonInfo) ={
    java.lang.reflect.Proxy.newProxyInstance(p.getClass.getClassLoader,p.getClass.getInterfaces,new NonOwnerInvocationHandler(p)).asInstanceOf[PersonInfo]
  }
}
